package org.apache.rocketmq.client.java.message;

import com.google.common.base.Objects;
import org.apache.rocketmq.client.java.clientapis.message.MessageId;

/**
 * @课程描述:从零带你写框架系列中的课程，整个系列包含netty，xxl-job，rocketmq，nacos，sofajraft，spring，springboot，disruptor，编译器，虚拟机等等。
 * @author：陈清风扬，个人微信号：chenqingfengyangjj。
 * @date:2025/6/16
 * @方法描述：消息Id
 */
public class MessageIdImpl implements MessageId {
    //消息Id版本号
    private final String version;
    //消息Id的后缀
    private final String suffix;

    public MessageIdImpl(String version, String suffix) {
        this.version = version;
        this.suffix = suffix;
    }


    @Override
    public String getVersion() {
        return version;
    }


    @Override
    public String toString() {
        if (MessageIdCodec.MESSAGE_ID_VERSION_V0.equals(version)) {
            return suffix;
        }
        return version + suffix;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        MessageIdImpl messageId = (MessageIdImpl) o;
        return Objects.equal(version, messageId.version) && Objects.equal(suffix, messageId.suffix);
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(version, suffix);
    }
}
